import { toJS } from "mobx";
import { observable, action } from 'mobx';
import * as Apis from "../../apis/Api";

class ContractPageStore {

    @observable Card = {};
    @observable modeInfo = {};
    @observable billId = -1;
    @observable editParams = {};
    @observable pageWidth = 1200;

    @action
    getLayoutInfo=(billId)=>{
        this.Card = new weaCube.common.CardStore();
        this.billId = billId;
        const params = {contractId:billId};
        Apis.getModeInfo(params).then(data => {
            if(data.status!=="0"){
                this.modeInfo = data;
                let billParams = data;
                if(typeof(data.viewLoyoutid)!=="undefined"){
                    billParams = {...data,layoutid:billParams.viewLoyoutid};
                }
                delete billParams.layoutid;
                const billParams1 = {...billParams,billid: billId,opentype:0,type:0,viewfrom:'fromsearchlist',guid:'card'}
                this.editParams = billParams1;
                this.Card.init(billParams1);
                this.Card.modeExcel.containerWidth = this.pageWidth;
            }
            
        });
    }
   

    @action
    setBill = (billId, otherParams) => {
        const params = { type: 0, modeId: otherParams.modeId, formId: otherParams.formId, billid: billId };
        this.Card.init(params);
        this.Card.modeExcel.containerWidth = this.pageWidth;
    }

    @action
    setEditBill = (params) => {
        const modeInfo = {...toJS(this.editParams),...params};
        delete modeInfo.layoutid;
        this.Card.init(modeInfo);
        this.Card.modeExcel.containerWidth = this.pageWidth;
    }

    @action 
    initPageWidth = (width=1200) =>{
        this.pageWidth = width;
    }
}

export default ContractPageStore;